package com.TIEmulator;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class TIEmulatorSettings
{
  private static final String EULA_ACCEPTED = "eula.accepted";
  private static final String NOTICE_ACCEPTED = "notice.accepted";
  private static final String POSSES_TI = "posess_ti";
  private static final String PREFERENCES_TIEMU = "tiemulator";
  private static final String ROM_DIR_SET = "rom_directory";
  private static final String ROM_FN_SET = "rom_filename";
  public static String SETUP_FILE = ".setup";
  private static final String STARTUP_COUNT_SET = "startup_count";
  private static final String USE_SD = "use_sd";
  private Context mCtx = null;
  private SharedPreferences mPref = null;

  public TIEmulatorSettings(Context paramContext)
  {
    this.mCtx = paramContext;
    this.mPref = checkGetPref();
  }

  private SharedPreferences checkGetPref()
  {
    if (this.mCtx == null);
    for (SharedPreferences localSharedPreferences = null; ; localSharedPreferences = this.mCtx.getSharedPreferences("tiemulator", 0))
      return localSharedPreferences;
  }

  public boolean WriteNativeSettings()
  {
    try
    {
      String str1 = getCurrRomFn();
      String str2 = getCurrDir();
      if (str1 == null)
        break label165;
      if (str2 == null)
        break label165;
      FileOutputStream localFileOutputStream = this.mCtx.openFileOutput(SETUP_FILE, 1);
      OutputStreamWriter localOutputStreamWriter = new OutputStreamWriter(localFileOutputStream);
      localOutputStreamWriter.write("SD_DIR:" + str2 + "\n");
      localOutputStreamWriter.write("IMG_FILE:" + str1 + "\n");
      localOutputStreamWriter.flush();
      localOutputStreamWriter.close();
      localFileOutputStream.close();
      i = 1;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
      Log.e(super.toString(), "Cannot write native settings correctly!");
      i = 0;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      Log.e(super.toString(), "Cannot write native settings correctly!");
      i = 0;
    }
    label165: int i = 0;
    return i;
  }

  public String getCurrDir()
  {
    if (this.mPref == null);
    for (String str = null; ; str = this.mPref.getString("rom_directory", null))
      return str;
  }

  public String getCurrRomFn()
  {
    if (this.mPref == null);
    for (String str = null; ; str = this.mPref.getString("rom_filename", null))
      return str;
  }

  public boolean getEulaAccepted()
  {
    if (this.mPref == null);
    for (boolean bool = false; ; bool = this.mPref.getBoolean("eula.accepted", false))
      return bool;
  }

  public String getFnPath()
  {
    if (this.mPref == null);
    for (String str = null; ; str = this.mPref.getString("rom_directory", null) + this.mPref.getString("rom_filename", null))
      return str;
  }

  public boolean getLegalNoticeAccepted()
  {
    if (this.mPref == null);
    for (boolean bool = false; ; bool = this.mPref.getBoolean("notice.accepted", false))
      return bool;
  }

  public boolean getPossesTI()
  {
    if (this.mPref == null);
    for (boolean bool = false; ; bool = this.mPref.getBoolean("posess_ti", false))
      return bool;
  }

  public int getStartupCount()
  {
    if (this.mPref == null);
    for (int i = -1; ; i = this.mPref.getInt("startup_count", 0))
      return i;
  }

  public boolean getUseSD()
  {
    if (this.mPref == null);
    for (boolean bool = false; ; bool = this.mPref.getBoolean("use_sd", false))
      return bool;
  }

  public void incStartupCount()
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      int i = this.mPref.getInt("startup_count", 0);
      if (i < 2147483647);
      this.mPref.edit().putInt("startup_count", ++i).commit();
    }
  }

  public void setCurrDir(String paramString)
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      this.mPref.edit().putString("rom_directory", paramString).commit();
    }
  }

  public void setCurrRomFn(String paramString)
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      this.mPref.edit().putString("rom_filename", paramString).commit();
    }
  }

  public void setEulaAccepted()
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      this.mPref.edit().putBoolean("eula.accepted", true).commit();
    }
  }

  public void setLegalNoticeAccepted()
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      this.mPref.edit().putBoolean("notice.accepted", true).commit();
    }
  }

  public void setPossesTI(boolean paramBoolean)
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      this.mPref.edit().putBoolean("posess_ti", paramBoolean).commit();
    }
  }

  public void setUseSD(boolean paramBoolean)
  {
    if (this.mPref == null);
    while (true)
    {
      return;
      this.mPref.edit().putBoolean("use_sd", paramBoolean).commit();
    }
  }
}
